"""helloDjangoPython URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls.conf import include
from django.views.generic.base import TemplateView, RedirectView  # 注意加上这句

from django.views.static import serve
from django.conf import settings 
from django.conf.urls import url, handler404

from . import views

urlpatterns = [
    path('admin/', admin.site.urls),
    
    path('', TemplateView.as_view(template_name="index.html")),
  
    url(r'^favicon.ico$', RedirectView.as_view(url=r'resource/favicon.ico')),
     # url(r'^favicon.ico$',serve, {'document_root': settings.BASE_ROOT_DIR}),
    # path('favicon.ico', serve, {'path': 'resource/favicon.ico'}),
    
    url(r'^upload/(?P<path>.*)$', serve, {'document_root':settings.UPLOADFILES_DIRS}),
    
    url(r'^c3fc7resource/(?P<path>.*)$', serve, {'document_root':settings.UPLOADFILES_DIRS}),
    
    # 增加以下一行，以识别静态资源
    url(r'^resource/(?P<path>.*)$', serve, {'document_root': settings.STATIC_ROOT}),
    # url(r'^favicon.ico$', serve, {'document_root': settings.STATIC_ROOT}),
    
    path('demo/', include('demo.urls')),
    
    url(r'^menu$', views.menu),
    
    url('readurl$', views.readurl),
    
]

handler404 = TemplateView.as_view(template_name="index.html")
